package sbc.corso;

import corso.lang.*;
import sbc.corso.*;

public class WriteExample {
	
    private CorsoVarOid sensorOid;
    private CorsoVarOid platinenOid;
	
	public WriteExample()	{
		
        sensorOid = new CorsoVarOid ();
        platinenOid = new CorsoVarOid ();
		
	}
	
	 public WriteExample (String myid)  {
		 
		 try	{
		 
		 
			 CorsoConnection myCorsoConnection = CorsoUtil.getCorsoConnection();
			 CorsoVarOid platineOid = new CorsoVarOid ();
	
		        try 
		        { 
		        	platineOid = myCorsoConnection.getNamedVarOid (myid, 
		        										CorsoUtil.SITE, 
		                                                null, 
		                                                false, 
		                                                CorsoConnection.NO_TIMEOUT); 
		        } 
		        catch (CorsoException e1) 
		        { 
		          try 
		          { 
		        	  platineOid = myCorsoConnection.createNamedVarOid (myCorsoConnection.getCurrentStrategy(),myid, null);
		        	  System.out.println("createNamedVarOid");
		          } 
		          catch (CorsoException e2) 
		          { 
		            System.out.println ("1Exception: Cannot create named oid " + e2); 
		            System.exit (-1); 
		          } 
		        } 
	        System.out.println ("creating/getting named oid - ok"); 
	 
	        SensorSharable testSensorSharable = new SensorSharable("1234567890", "NICHT MONTIERT");
	        // create data structure and fill with data *************************** 
	        PlatineSharable myPlatineSharable = new PlatineSharable ("platine 12", testSensorSharable, testSensorSharable, "NICHT MONTIERT"); 
	        System.out.println("hallo");
	        // write the individual data structure to oid ************************* 
	        platineOid.writeShareable (myPlatineSharable, CorsoConnection.INFINITE_TIMEOUT); 
	        System.out.println ("writing data to named oid - ok"); 
	        System.out.println ("start Sample3b to see the effect"); 
	 
	        // disconnect from CORSO ********************************************** 
	        myCorsoConnection.disconnect (); 
		 }
         catch (CorsoWriteException e2)
         {
             System.out.println ("2Cannot create named oid " + e2);
             System.exit (-4);
         }
         catch (CorsoException e2)
         {
             System.out.println ("3Cannot create named oid " + e2);
             System.exit (-4);
         }
		 
	 }
	 
	 public static void main(String [] args)	{
		 new WriteExample("Platine");
	 }
}